package com.itheima.demo1;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class asd {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

                             //读取properties文件
        FileReader fr = new FileReader("G:\\heina Day 1\\misao\\src\\porg.properties");

    //创建properties集合
        Properties p = new Properties();

//从properties文件中读取属性
        p.load(fr);
        fr.close();
    //返回一个全限定名
        String s = (String) p.get("classname");

        //返回一个Class对象
        Class clazz = Class.forName(s);
        //创建一个无参构造
        Constructor constructor = clazz.getConstructor();

        //通过无参构造创建一个对象
        Object o = constructor.newInstance();
        //通过类对象获得eat方法
        Method method = clazz.getMethod("eat");
        //接收方法运行后的返回值并打印
            method.invoke(o);

}
}